<?php

use Biz\service\brand\BlindBox;
use Biz\cache\brand\BrandShowActivity;

/**
 * 更换盲盒
 */
class ChangeBoxAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;

    public function main()
    {
        if (!BrandShowActivity::isLock($this->uid . '-blind-box', 2)) {
            $boxId = $this->getRequest()->getPost('box_id', 0);
            $boxMap = BlindBox::getBlindBox($this->uid);
            $allBoxId = array_keys($boxMap);
            if (!$boxId || !in_array($boxId, $allBoxId)) {
                throw new \Exception('参数错误');
            }
            $res = BlindBox::changeBox($this->uid, $boxId);
            $this->setSuccess(['box_info' => $res]);
        } else {
            throw new \Exception('你的操作太频繁');
        }
    }
}